package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.io.FileDescriptor;
import java.io.PrintWriter;

public class rmbrate extends AppCompatActivity {
    private static final String TAG ="rmbrate";
    private EditText inpDollar;
    private EditText inpEuro;
    private EditText inpWon;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_rmbrate);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        inpDollar =findViewById(R.id.dollar_rate);
        inpEuro =findViewById(R.id.euro_rate);
        inpWon =findViewById(R.id.won_rate);

        Intent intent=getIntent();
        float dollar = intent.getFloatExtra("key_dollar",0.1f);
        float euro = intent.getFloatExtra("key_euro",0.1f);
        float won = intent.getFloatExtra("key_won",0.1f);

        inpDollar.setText(String.valueOf(dollar));
        inpEuro.setText(String.valueOf(euro));
        inpWon.setText(String.valueOf(won));
    }
    public void save(View bt){
        String dollarStr =inpDollar.getText().toString();
        String euroStr =inpEuro.getText().toString();
        String wonStr =inpWon.getText().toString();
        try{
            float dollar =Float.parseFloat(dollarStr);
            float euro =Float.parseFloat(euroStr);
            float won =Float.parseFloat(wonStr);

            Intent retIntent = getIntent();
            Bundle bdl =new Bundle();
            bdl.putFloat("ret_dollar",dollar);
            bdl.putFloat("ret_euro",euro);
            bdl.putFloat("ret_won",won);
            retIntent.putExtras(bdl);
            setResult(3,retIntent);

            finish();
        }catch (NumberFormatException e){
            Log.e(TAG, "出错", e);
        }
    }
}
